import { defineStore } from "pinia";
//仓库键名必须是use开头并且具有唯一性
import { userToast } from "./keys";

//提示传入参数
type ToastParams = {
  isShow?: boolean;
  msg?: string;
  type?: string;
};

type ToastState = {
  isToast?: boolean;
  toastMsg?: string;
  toastType?: string;
};

//管理提示框是否显示
export const useToastStore = defineStore("userToast", {
  state(): ToastState {
    return {
      isToast: false, //是否显示提示框
      toastMsg: "", //提示内容
      toastType: "", //提示类型 success成功 error出错 warning警告
    };
  },
  getters: {},
  actions: {
    ToastShowModel(payload: ToastParams) {
      this.isToast = payload.isShow;
      if (payload.isShow) {
        this.toastMsg = payload.msg;
        this.toastType = payload.type;
      }
      setTimeout(() => {
        this.isToast = false;
      }, 2000);
    },
  },
});
